package com.aloda.service.impl;

import com.aloda.dto.OperationLogPageDTO;
import com.aloda.entity.OperationLog;
import com.aloda.mapper.OperationLogMapper;
import com.aloda.result.PageResult;
import com.aloda.service.OperationLogService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OperationLogServiceImpl implements OperationLogService {

    @Autowired
    private OperationLogMapper operationLogMapper;

    /**
     * 操作日志分页查询
     *
     * @param pageDTO
     * @return
     */
    @Override
    public PageResult pageQuery(OperationLogPageDTO pageDTO) {
        //转化为北京时间
        if(pageDTO.getEnd()!=null&&pageDTO.getBegin()!=null){
            pageDTO.setBegin(pageDTO.getBegin().plusHours(8));
            pageDTO.setEnd(pageDTO.getEnd().plusHours(8));
        }

        PageHelper.startPage(pageDTO.getPage(), pageDTO.getPageSize());
        Page<OperationLog> page = operationLogMapper.pageQuery(pageDTO);
        PageResult pageResult = new PageResult(page.getTotal(),page.getResult());
        return pageResult;
    }

    /**
     * 删除操作日志
     *
     * @param ids
     */
    @Override
    public void delete(List<Long> ids) {
        operationLogMapper.delete(ids);
    }
}
